%���㽻�棬��select������ķ���������Ͻ���
function [CX_chrome1,CX_chrome2]=Cross(chrom1,chrom2,m_no,CUTMachineDis)

    temp=size(chrom1,2);   
    Cross_schedule_1=zeros(1,m_no);
    Cross_schedule_2=zeros(1,temp-m_no);

        Parent1_schedule=chrom1(1,1:m_no);
        Parent2_schedule=chrom2(1,1:m_no);
        Parent3_schedule=chrom1(1,m_no+1:m_no+m_no);
        Parent4_schedule=chrom2(1,m_no+1:m_no+m_no);   
        %����������������,Point1<Point2
        Temp1=ceil(m_no*rand);
        if Temp1==0 
            Temp1=1; 
        end
        Temp2=ceil(m_no*rand);
        if Temp2==0 
            Temp2=1; 
        end
        while (Temp1==Temp2)
            Temp2=ceil(m_no*rand); 
            if Temp2==0 
                Temp2=1; 
            end
        end
        Point2=max(Temp1,Temp2);
        Point1=min(Temp1,Temp2);
        %Point1ǰ��Ƭ��ֱ��copy
        for j=1:Point1-1
            Cross_schedule_1(j)=Parent1_schedule(j);
            Cross_schedule_2(j)=Parent2_schedule(j);
            Cross_schedule_3(j)=Parent3_schedule(j);
            Cross_schedule_4(j)=Parent4_schedule(j);
        end
        %Point2���Ƭ��ֱ��copy
        for j=Point2+1:m_no
            Cross_schedule_1(j)=Parent1_schedule(j);
            Cross_schedule_2(j)=Parent2_schedule(j);
            Cross_schedule_3(j)=Parent3_schedule(j);
            Cross_schedule_4(j)=Parent4_schedule(j);
        end
        %�ɶԱ�ǳ����������彻��Ƭ�ζ����ڵĲ�����ţ�����ͬһ����������ͬ�ı������ѡ��������ֵĲ�����š�
        %����Cross_schedule(i)
        Temp_part_no1=zeros(1,m_no); %��¼�������ֵĴ���
        Unassigned=0; %��¼δ�ҵ�ƥ��Ĺ�������
        Unassigned_mach=0;
        for j=Point1:Point2
            Temp_part=Parent1_schedule(j);
            Temp_mach=Parent3_schedule(j);
            Temp_part_no1(Temp_part)=Temp_part_no1(Temp_part)+1;
            Temp_part_no2=0;
            Logic=0;
            for k=Point1:Point2
                if Temp_part==Parent2_schedule(k);
                    Temp_part_no2=Temp_part_no2+1;
                        Cross_schedule_1(k)=Temp_part;
%                         Cross_schedule_3(k)=Temp_mach;
                        Logic=1;
                end                
            end
            if Logic==0
                if Unassigned==0
                    Unassigned=Temp_part;
                else
                    Unassigned=[Unassigned,Temp_part];
                    
                end
            end
        end
        Temp_no=0;
        for j=Point1:Point2
            if Cross_schedule_1(j)==0
                Temp_no=Temp_no+1;
                Cross_schedule_1(j)=Unassigned(Temp_no);
%                 Cross_schedule_3(j)=Unassigned_mach(Temp_no);

            end            
        end

        %����Cross_schedule(i+1)
        Temp_part_no1=zeros(m_no); %��¼�������ֵĴ���
        Unassigned=0; %��¼δ�ҵ�ƥ��Ĺ�������
        Unassigned_mach=0;
        for j=Point1:Point2
            Temp_part=Parent2_schedule(j);
%             Temp_mach=Parent4_schedule(j);
            Temp_part_no1(Temp_part)=Temp_part_no1(Temp_part)+1;
            Temp_part_no2=0;
            Logic=0;
            for k=Point1:Point2
                if Temp_part==Parent1_schedule(k);
                    Temp_part_no2=Temp_part_no2+1;
                    if Temp_part_no1(Temp_part)==Temp_part_no2
                        Cross_schedule_2(k)=Temp_part;
%                         Cross_schedule_4(k)=Temp_mach;                        
                        Logic=1;                        
                    end
                end 
            end
            if Logic==0
                if Unassigned==0
                    Unassigned=Temp_part;
                else
                    Unassigned=[Unassigned,Temp_part];                    
                end
                if Unassigned_mach==0
                    Unassigned_mach=Temp_mach;
                else
                    Unassigned_mach=[Unassigned_mach,Temp_mach];                    
                end
            end
        end
        Temp_no=0;
        for j=Point1:Point2
            if Cross_schedule_2(j)==0
                Temp_no=Temp_no+1;
                Cross_schedule_2(j)=Unassigned(Temp_no);
%                 Cross_schedule_4(j)=Unassigned_mach(Temp_no);
            end 
        end
%% �м䲿�� ���н���
%        z= rand(1,Point2-Point1+1);
%        y=rand(1,Point2-Point1+1);
%        for i=Point1:Point2
%            if z(i-Point1+1)>0.5
%              temp=find(Parent2_schedule==Cross_schedule_1(i));
%              Cross_schedule_3(i)= Parent4_schedule(temp);
%            else
%              temp=find(Parent1_schedule==Cross_schedule_1(i));
%              Cross_schedule_3(i)= Parent3_schedule(temp);
%            end
%             if y(i-Point1+1)>0.5
%              temp=find(Parent1_schedule==Cross_schedule_2(i));
%              Cross_schedule_4(i)= Parent3_schedule(temp);
%            else
%              temp=find(Parent2_schedule==Cross_schedule_2(i));
%              Cross_schedule_4(i)= Parent4_schedule(temp);
%            end
%        end

%% ȫ�� ���н���
                   z= rand(1,m_no);
       y=rand(1,m_no);
       for i=1:m_no
           if z(i)>0.5
             temp=find(Parent2_schedule==Cross_schedule_1(i));
             Cross_schedule_3(i)= Parent4_schedule(temp);
           else
             temp=find(Parent1_schedule==Cross_schedule_1(i));
             Cross_schedule_3(i)= Parent3_schedule(temp);
           end
            if y(i)>0.5
             temp=find(Parent1_schedule==Cross_schedule_2(i));
             Cross_schedule_4(i)= Parent3_schedule(temp);
           else
             temp=find(Parent2_schedule==Cross_schedule_2(i));
             Cross_schedule_4(i)= Parent4_schedule(temp);
           end
       end   
             
 % z�м佻��Ļ����������� 
%   for j=Point1:Point2
%             Temp_part1=Cross_schedule_1(j);
%             Temp_part2=Cross_schedule_2(j);
% 
%         %% Ϊpart2ѡ���Ӧ�Ļ���
%         machineAvailable=CUTMachineDis(2:end,Temp_part1); %%�ҳ���Ӧ���������õĻ��� ����
%         temp=ceil((size(CUTMachineDis,1)-1)*rand);  %%���ѡ��һ̨����
%  %%��ʹ�õĻ������и�ֵ
%         Cross_schedule_3(j)=machineAvailable(temp);
% 
%         while(Cross_schedule_3(j)==0)                   %%���ѡ��Ļ������ܱ�ʹ��  Ҳ����0����ѭ������ѡ��
%             temp=ceil((size(CUTMachineDis,1)-1)*rand);
%             Cross_schedule_3(j)=machineAvailable(temp);
%         end
%         
%         %% Ϊpart3ѡ���Ӧ�Ļ���
%           machineAvailable=CUTMachineDis(2:end,Temp_part2); %%�ҳ���Ӧ���������õĻ��� ����
%          temp=ceil((size(CUTMachineDis,1)-1)*rand);  %%���ѡ��һ̨����
%  %%��ʹ�õĻ������и�ֵ
%         Cross_schedule_4(j)=machineAvailable(temp);
% 
%         while(Cross_schedule_4(j)==0)                   %%���ѡ��Ļ������ܱ�ʹ��  Ҳ����0����ѭ������ѡ��
%             temp=ceil((size(CUTMachineDis,1)-1)*rand);
%             Cross_schedule_4(j)=machineAvailable(temp);
%         end
%       
%   end
        
        %% �Ժ���Ļ����������2�㽻��
         CX_chrome1=[Cross_schedule_1,Cross_schedule_3];
         CX_chrome2=[Cross_schedule_2,Cross_schedule_4];
     end
    


